package com.fbs.wowo;

import com.fbs.wowo.config.OriginFilterConfig;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.util.unit.DataSize;

import javax.servlet.MultipartConfigElement;

@MapperScan("com.fbs.wowo.*.mapper")
@SpringBootApplication
public class WowoApplication {
    public static String[] args = null;
    public static void main(String[] args) {
        WowoApplication.args = args;
        SpringApplication.run(WowoApplication.class, args);
    }

    /**
     * 跨域
     * @return
     */
    @Bean
    public FilterRegistrationBean setFilter(){
        FilterRegistrationBean filterBean = new FilterRegistrationBean();
        filterBean.setFilter(new OriginFilterConfig());
        filterBean.setName("OriginFilterConfig");
        filterBean.addUrlPatterns("/*");
        return filterBean;
    }

    /**
     * 上传大小配置
     * @return
     */
    @Bean
    public MultipartConfigElement multipartConfigElement(){
        MultipartConfigFactory config = new MultipartConfigFactory();
        config.setMaxFileSize(DataSize.ofBytes(80 * 1024 * 1024));
        config.setMaxRequestSize(DataSize.ofBytes(100 * 1024 * 1024));
        return config.createMultipartConfig();
    }

}

